package com.old.mapper;

import com.github.pagehelper.Page;
import com.old.annotation.AutoFill;
import com.old.dto.VideoCommentDTO;
import com.old.dto.VideoCommentQueryDTO;
import com.old.entity.VideoComment;
import com.old.enumeration.OperationType;
import com.old.vo.VideoCommentVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface VideoCommentMapper {
    /**
     * 根据postId查询戏曲评论
     * @param videoComment
     * @return
     */
    List<VideoComment> list(VideoComment videoComment);

    /**
     * 添加评论
     * @param videoComment
     */
    @Insert("INSERT INTO videocommentList(comment_authorId,comment,create_time,video_id) " +
            "VALUES(#{commentAuthorId}, #{comment},  #{createTime}, #{videoId})")
   // @Options(useGeneratedKeys = true, keyProperty = "video_commentList_id")
    // 获取自增主键
    @AutoFill(OperationType.INSERT)
    void add(VideoCommentDTO videoComment);

//    /**
//     * 分页查询评论
//     * @param videoCommentQueryDTO
//     * @return
//     */
//    @Select("SELECT * FROM videocommentList WHERE video_id = #{videoId} ORDER BY create_time DESC")
//    Page<VideoComment> listPage(VideoCommentQueryDTO videoCommentQueryDTO);


    @Select("SELECT c.*, u.name as commentName,u.avatar as commentAvatar " +
            "FROM videocommentList c " +
            "LEFT JOIN user u ON c.comment_authorId = u.id " +
            "WHERE c.video_id = #{videoId} " +
            "ORDER BY c.create_time DESC")
    Page<VideoCommentVO> listPage(@Param("videoId") Integer videoId);
}
